import Dexie from 'dexie';

class DexieMgr {
  async db() {
    if (this._db == null) {
      console.log("dexie inited")
      this._db = new Dexie('lzs.db');
      this._db.version(25).stores({
        // api: api_url
        // session: 账号的string session
        actives: '++id, &value',
        // env: node|web，表示该账号登录的环境
        // status: 登录状态
        accounts: '++id, &phone, password, session, api, proxy, updatetime, wallet_address, wallet_address_user_friendly, eth_wallet_address, eth_wallet_signature, mnemonic, env, status',
        // description: 游戏介绍  strategy: 游戏策略, gameUrl: 游戏入口url, botUrl: 游戏机器人url, channelUrl: 游戏频道url
        // inviteList: 用户填入的邀请链接数组，会自动平均分配到所有账号游戏中
        // name: 游戏表名
        projects: '++id, &bot, route, &name, icon, description, strategy, channel, gameUrl, inviteList',
        proxy: '++id, proxy',
        hamster: '++id, &phone, tgweb, token, tokenupdate, gameupdate, count, speed, score, airdrop_address, error, airdrop',
        piggy: '++id, &phone, tgweb, token, tokenupdate, gameupdate, count, score, error, isJoinChannel, isJoinBot, inviteUrl',
        blum: '++id, &phone, tgweb, token, tokenupdate, gameupdate, count, score, error, registed, isJoinChannel, isJoinBot, inviteUrl',
        tonstation: '++id, &phone, tgweb, token, tokenupdate, gameupdate, count, score, error, registed, isJoinChannel, isJoinBot, inviteUrl',
        duckchain: '++id, &phone, tgweb, token, tokenupdate, gameupdate, count, score, error, registed, isJoinChannel, isJoinBot, inviteUrl',
        timefarm: '++id, &phone, tgweb, token, tokenupdate, gameupdate, count, score, error, registed, isJoinChannel, isJoinBot, inviteUrl',
        vana: '++id, &phone, tgweb, token, tokenupdate, gameupdate, count, score, error, registed, isJoinChannel, isJoinBot, inviteUrl',
        tabizoo: '++id, &phone, tgweb, token, tokenupdate, gameupdate, count, score, error, isJoinChannel, isJoinBot, inviteUrl',
        cats: '++id, &phone, tgweb, token, tokenupdate, gameupdate, count, score, error, isJoinChannel, isJoinBot, inviteUrl',
        major: '++id, &phone, tgweb, token, tokenupdate, gameupdate, count, score, error, isJoinChannel, isJoinBot, inviteUrl',
        memefi: '++id, &phone, tgweb, token, tokenupdate, gameupdate, count, score, error, isJoinChannel, isJoinBot, inviteUrl, currentBoss_currentHealth, currentBoss_level, airdrop_wallet',
        cows: '++id, &phone, tgweb, token, tokenupdate, gameupdate, count, score, error, isJoinChannel, isJoinBot, inviteUrl',
        tomarket: '++id, &phone, tgweb, token, tokenupdate, gameupdate, count, score, error, isJoinChannel, isJoinBot, inviteUrl, airdrop',
        sidekick: '++id, &phone, tgweb, token, tokenupdate, gameupdate, count, score, error, isJoinChannel, isJoinBot, inviteUrl',
      });
    }
    if (this._db.isOpen() == false) {
      await this._db.open()
    }
    return this._db;
  }
}

const DexieCtx = new DexieMgr()

export default DexieCtx